#include "slepbase.h"
#include "cslep.h"

void testRunMTLogisticR(){ // corrected machi ;)
	int i;
	OPTS opts;
	slep_matrix* A;
	slep_vector *y, *funVal, *LValue, *c_v;
	slep_matrix* X;
	int ind[] = {0,100,200,300,400,500,600,700,800,900,1000};
	double rho;
	stopWatch timer;

	A = slepAllocDenseMatrix(1000,100);
	X = slepAllocDenseMatrix(100,10);
	y = slepAllocDenseVector(1000);
	c_v = slepAllocDenseVector(10);
	funVal = slepAllocDenseVector(100);
	LValue = slepAllocDenseVector(100);

	slep_randn(A->data.mtrx,1000*100,0.,1.);
	slep_randn(y->data.vctr,1000,0.,1.);
	for(i=0; i<y->dim; ++i)
		y->data.vctr[i]= (y->data.vctr[i]>0)? 1.0 : -1.0;

	opts.ind = ind;
	opts.ind_size = 11;

	opts.lFlag=0;
	opts.mFlag=0;
	opts.nFlag=0;
	opts.rFlag=1;

	opts.rsL2=0;
	opts.maxIter=100;

	slepWriteDenseMatrix("A-LogR.slm",A);
	slepWriteDenseVector("y-LogR.slv",y);
	opts.init = 2;
	opts.tFlag=5;
	opts.maxIter = 100;
	opts.REGISTER = SlepOPT_maxIter | SlepOPT_rsL2 | SlepOPT_indices;

	opts.rsL2 = 0.0;
	opts.rFlag = 1;
	rho=0.4;

	opts.mFlag=0;
	opts.lFlag=0;
	startTimer(&timer);
	mtLogisticR(A,y,rho,&opts,X,c_v,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-LogR-1.slm",X);
	slepVerboseWriteDenseVector("f-LogR-1.slv",funVal);
	slepVerboseWriteDenseVector("L-LogR-1.slv",LValue);

	opts.mFlag=1;
	startTimer(&timer);
	mtLogisticR(A,y,rho,&opts,X,c_v,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-LogR-2.slm",X);
	slepVerboseWriteDenseVector("f-LogR-2.slv",funVal);
	slepVerboseWriteDenseVector("L-LogR-2.slv",LValue);

	opts.lFlag=1;
	opts.mFlag=1;
	startTimer(&timer);
	mtLogisticR(A,y,rho,&opts,X,c_v,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-LogR-3.slm",X);
	slepVerboseWriteDenseVector("f-LogR-3.slv",funVal);
	slepVerboseWriteDenseVector("L-LogR-3.slv",LValue);
}